home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / httrack-3.33.exe / {app} / src / htscore.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-11  |  14.3 KB  |  442 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Main file .h                                           */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38. #ifndef HTTRACK_DEFH
  39. #define HTTRACK_DEFH
  40.  
  41.  
  42. #include "htsglobal.h"
  43.  
  44. /* specific definitions */
  45. #include "htsbase.h"
  46. // Includes & dΘfinitions
  47. #ifdef HAVE_SYS_TYPES_H
  48. #include <sys/types.h>
  49. #endif
  50. #ifdef HAVE_SYS_STAT_H
  51. #include <sys/stat.h>
  52. #endif
  53. #ifdef _WIN32
  54. #ifndef  _WIN32_WCE
  55. #include <conio.h>
  56. #endif
  57. #ifndef  _WIN32_WCE
  58. #include <signal.h>
  59. #include <direct.h>
  60. #else
  61. #ifndef HTS_CECOMPAT
  62. #include "signal.h"
  63. #endif
  64. #endif
  65. #else
  66. #include <signal.h>
  67. #ifdef HAVE_UNISTD_H
  68. #include <unistd.h>
  69. #endif
  70. #endif
  71. /* END specific definitions */
  72.  
  73.  
  74. // Include htslib.h for all types
  75. #include "htslib.h"
  76.  
  77. #include "htsopt.h"
  78.  
  79. // structure d'un lien
  80. typedef struct lien_url {
  81.   char firstblock;      // flag 1=premier malloc 
  82.   char link_import;     // lien importΘ α la suite d'un moved - ne pas appliquer les rΦgles classiques up/down
  83.   int depth;            // profondeur autorisΘe lien ; >0 forte 0=faible
  84.   int pass2;            // traiter aprΦs les autres, seconde passe. si == -1, lien traitΘ en background
  85.   int premier;          // pointeur sur le premier lien qui a donnΘ lieu aux autres liens du domaine
  86.   int precedent;        // pointeur sur le lien qui a donnΘ lieu α ce lien prΘcis
  87.   //int moved;          // pointeur sur moved
  88.   int retry;            // nombre de retry restants
  89.   int testmode;         // mode test uniquement, envoyer juste un head!
  90.   char* adr;            // adresse
  91.   char* fil;            // nom du fichier distant
  92.   char* sav;            // nom α sauver sur disque (avec chemin Θventuel)
  93.   char* cod;            // chemin codebase Θventuel si classe java
  94.   char* former_adr;     // adresse initiale (avant Θventuel moved), peut Ωtre nulle
  95.   char* former_fil;     // nom du fichier distant initial (avant Θventuel moved), peut Ωtre nul
  96.   // pour optimisation:
  97. #if HTS_HASH
  98.   int hash_next[3];     // prochain lien avec mΩme valeur hash
  99. #else
  100.   int sav_len;          // taille de sav
  101. #endif
  102. } lien_url;
  103.  
  104. // chargement de fichiers en 'arriΦre plan'
  105. typedef struct lien_back {
  106. #if DEBUG_CHECKINT
  107.   char magic;
  108. #endif
  109.   char url_adr[HTS_URLMAXSIZE*2];     // adresse
  110.   char url_fil[HTS_URLMAXSIZE*2];     // nom du fichier distant
  111.   char url_sav[HTS_URLMAXSIZE*2];     // nom α sauver sur disque (avec chemin Θventuel)
  112.   char referer_adr[HTS_URLMAXSIZE*2]; // adresse host page referer
  113.   char referer_fil[HTS_URLMAXSIZE*2]; // fichier page referer
  114.   char location_buffer[HTS_URLMAXSIZE*2];  // "location" en cas de "moved" (302,..)
  115.   char* tmpfile;                           // nom α sauver temporairement (compressΘ)
  116.   char tmpfile_buffer[HTS_URLMAXSIZE*2];   // buffer pour le nom α sauver temporairement
  117.   char send_too[1024];    // donnΘes α envoyer en mΩme temps que le header
  118.   int status;             // status (-1=non utilisΘ, 0: prΩt, >0: opΘration en cours)
  119.   int testmode;           // mode de test
  120.   int timeout;            // gΘrer des timeouts? (!=0  : nombre de secondes)
  121.   TStamp timeout_refresh; // si oui, time refresh
  122.   int rateout;            // timeout refresh? (!=0 : taux minimum tolΘrΘ en octets/s)
  123.   TStamp rateout_time;    // si oui, date de dΘpart
  124.   LLint maxfile_nonhtml;  // taille max d'un fichier non html
  125.   LLint maxfile_html;     // idem pour un ficheir html
  126.   htsblk r;               // structure htsblk de chaque objet en background 
  127.   int is_update;          // mode update
  128.   int head_request;       // requΦte HEAD?
  129.   LLint range_req_size;   // range utilisΘ
  130.   TStamp ka_time_start;   // refresh time for KA 
  131.   //
  132.   int http11;             // L'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  133.   int is_chunk;           // chunk?
  134.   char* chunk_adr;        // adresse chunk en cours de chargement
  135.   LLint chunk_size;       // taille chunk en cours de chargement
  136.   LLint chunk_blocksize;  // taille data declaree par le chunk
  137.   LLint compressed_size;  // taille compressΘs (stats uniquement)
  138.   //
  139.   int* pass2_ptr;         // pointeur sur liens[ptr]->pass2
  140.   //
  141.   char info[256];         // Θventuel status pour le ftp
  142.   int stop_ftp;           // flag stop pour ftp
  143.   int finalized;          // finalized (optim memory)
  144. #if DEBUG_CHECKINT
  145.   char magic2;
  146. #endif
  147. } lien_back;
  148.  
  149. typedef struct cache_back_zip_entry cache_back_zip_entry;
  150.  
  151. // cache
  152. typedef struct cache_back {
  153.   int version;        // 0 ou 1
  154.   /* */
  155.   int type;
  156.   int ro;
  157.   FILE *dat,*ndx,*olddat;
  158.   char *use;      // liste des adr+fil
  159.   FILE *lst;      // liste des fichiers pour la "purge"
  160.   FILE *txt;      // liste des fichiers (info)
  161.   char lastmodified[256];
  162.   // HASH
  163.   void* hashtable;
  164.   // HASH for tests (naming subsystem)
  165.   void* cached_tests;
  166.   // fichiers log optionnels
  167.   FILE* log;
  168.   FILE* errlog;
  169.   // variables
  170.   int ptr_ant;      // pointeur pour anticiper
  171.   int ptr_last;     // pointeur pour anticiper
  172.   //
  173.   void* zipInput;
  174.   void* zipOutput;
  175.   cache_back_zip_entry* zipEntries;
  176.   int zipEntriesOffs;
  177.   int zipEntriesCapa;
  178. } cache_back;
  179.  
  180. typedef struct hash_struct {
  181.   lien_url** liens;                     // pointeur sur liens
  182.   int max_lien;                         // indice le plus grand rencontrΘ
  183.   int hash[3][HTS_HASH_SIZE];           // tables pour sav/adr-fil/former_adr-former_fil
  184. } hash_struct;
  185.  
  186. #if HTS_HASH
  187. #else
  188. #define hash_write(A,B)
  189. #endif
  190.  
  191. typedef struct filecreate_params {
  192.   FILE* lst;
  193.   char path[HTS_URLMAXSIZE*2];
  194. } filecreate_params;
  195.  
  196. /* Library internal definictions */
  197. #ifdef HTS_INTERNAL_BYTECODE
  198.  
  199. static int cache_writable(cache_back* cache) {
  200.   return (cache != NULL && ( cache->dat != NULL || cache->zipOutput != NULL ) );
  201. }
  202.  
  203. static int cache_readable(cache_back* cache) {
  204.   return (cache != NULL && ( cache->olddat != NULL || cache->zipInput != NULL ) );
  205. }
  206.  
  207. #endif
  208.  
  209. // Fonctions
  210.  
  211. // INCLUDES .H PARTIES DE CODE HTTRACK
  212.  
  213. // routine main
  214. #include "htscoremain.h"
  215.  
  216. // divers outils pour httrack.c
  217. #include "htstools.h"
  218.  
  219. // aide pour la version en ligne de commande
  220. #include "htshelp.h"
  221.  
  222. // gΘnΘration du nom de fichier α sauver
  223. #include "htsname.h"
  224.  
  225. // gestion ftp
  226. #include "htsftp.h"
  227.  
  228. // routine parser java
  229. #include "htsjava.h"
  230.  
  231. // gestion interception d'URL
  232. #include "htscatchurl.h"
  233.  
  234. // gestion robots.txt
  235. #include "htsrobots.h"
  236.  
  237. // routines d'acceptation de liens
  238. #include "htswizard.h"
  239.  
  240. // routines de regexp
  241. #include "htsfilters.h"
  242.  
  243. // gestion backing
  244. #include "htsback.h"
  245.  
  246. // gestion cache
  247. #include "htscache.h"
  248.  
  249. // gestion hashage
  250. #include "htshash.h"
  251. #include "htsinthash.h"
  252.  
  253. // gestion rΘentrance
  254. #include "htsnostatic.h"
  255.  
  256. // infos console
  257. #if HTS_ANALYSTE_CONSOLE
  258. #include "httrack.h"
  259. #endif
  260.  
  261. #include "htsdefines.h"
  262.  
  263. #include "hts-indextmpl.h"
  264.  
  265. // INCLUDES .H PARTIES DE CODE HTTRACK
  266.  
  267. //
  268.  
  269. /*
  270. typedef void  (* t_hts_htmlcheck_init)(void);
  271. typedef void  (* t_hts_htmlcheck_uninit)(void);
  272. typedef int   (* t_hts_htmlcheck_start)(httrackp* opt);
  273. typedef int   (* t_hts_htmlcheck_end)(void);
  274. typedef int   (* t_hts_htmlcheck_chopt)(httrackp* opt);
  275. typedef int   (* t_hts_htmlcheck_process)(char** html,int* len,char* url_adresse,char* url_fichier);
  276. typedef int   (* t_hts_htmlcheck)(char* html,int len,char* url_adresse,char* url_fichier);
  277. typedef char* (* t_hts_htmlcheck_query)(char* question);
  278. typedef char* (* t_hts_htmlcheck_query2)(char* question);
  279. typedef char* (* t_hts_htmlcheck_query3)(char* question);
  280. typedef int   (* t_hts_htmlcheck_loop)(lien_back* back,int back_max,int back_index,int lien_tot,int lien_ntot,int stat_time,hts_stat_struct* stats);
  281. typedef int   (* t_hts_htmlcheck_check)(char* adr,char* fil,int status);
  282. typedef void  (* t_hts_htmlcheck_pause)(char* lockfile);
  283. typedef void  (* t_hts_htmlcheck_filesave)(char* file);
  284. typedef int   (* t_hts_htmlcheck_linkdetected)(char* link);
  285. typedef int   (* t_hts_htmlcheck_linkdetected2)(char* link, char* tag_start);
  286. typedef int   (* t_hts_htmlcheck_xfrstatus)(lien_back* back);
  287. typedef int   (* t_hts_htmlcheck_savename)(char* adr_complete,char* fil_complete,char* referer_adr,char* referer_fil,char* save);
  288. typedef int   (* t_hts_htmlcheck_sendhead)(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* outgoing);
  289. typedef int   (* t_hts_htmlcheck_receivehead)(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* incoming);
  290. */
  291.  
  292. // demande d'interaction avec le shell
  293. #if HTS_ANALYSTE
  294. //char HTbuff[1024];
  295. /*
  296. extern t_hts_htmlcheck_init       hts_htmlcheck_init;
  297. extern t_hts_htmlcheck_uninit     hts_htmlcheck_uninit;
  298. extern t_hts_htmlcheck_start      hts_htmlcheck_start;
  299. extern t_hts_htmlcheck_end        hts_htmlcheck_end;
  300. extern t_hts_htmlcheck_chopt      hts_htmlcheck_chopt;
  301. extern t_hts_htmlcheck_process    hts_htmlcheck_preprocess;
  302. extern t_hts_htmlcheck_process    hts_htmlcheck_postprocess;
  303. extern t_hts_htmlcheck            hts_htmlcheck;
  304. extern t_hts_htmlcheck_query      hts_htmlcheck_query;
  305. extern t_hts_htmlcheck_query2     hts_htmlcheck_query2;
  306. extern t_hts_htmlcheck_query3     hts_htmlcheck_query3;
  307. extern t_hts_htmlcheck_loop       hts_htmlcheck_loop;
  308. extern t_hts_htmlcheck_check      hts_htmlcheck_check;
  309. extern t_hts_htmlcheck_pause      hts_htmlcheck_pause;
  310. extern t_hts_htmlcheck_filesave   hts_htmlcheck_filesave;
  311. extern t_hts_htmlcheck_linkdetected hts_htmlcheck_linkdetected;
  312. extern t_hts_htmlcheck_linkdetected2 hts_htmlcheck_linkdetected2;
  313. extern t_hts_htmlcheck_xfrstatus  hts_htmlcheck_xfrstatus;
  314. extern t_hts_htmlcheck_savename   hts_htmlcheck_savename;
  315. extern t_hts_htmlcheck_sendhead   hts_htmlcheck_sendhead;
  316. extern t_hts_htmlcheck_receivehead hts_htmlcheck_receivehead;
  317. */
  318.  
  319. /* Library internal definictions */
  320. #ifdef HTS_INTERNAL_BYTECODE
  321.  
  322. //
  323. #ifndef HTTRACK_DEFLIB
  324. HTSEXT_API int hts_is_parsing(int flag);
  325. HTSEXT_API int hts_is_testing(void);
  326. HTSEXT_API int hts_is_exiting(void);
  327. HTSEXT_API int hts_setopt(httrackp* opt);
  328. HTSEXT_API int hts_addurl(char** url);
  329. HTSEXT_API int hts_resetaddurl(void);
  330. HTSEXT_API int copy_htsopt(httrackp* from,httrackp* to);
  331. HTSEXT_API char* hts_errmsg(void);
  332. HTSEXT_API int hts_setpause(int);      // pause transfer
  333. HTSEXT_API int hts_request_stop(int force);
  334. //
  335. HTSEXT_API char* hts_cancel_file(char * s);
  336. HTSEXT_API void hts_cancel_test(void);
  337. HTSEXT_API void hts_cancel_parsing(void);
  338. #endif
  339. //
  340. // Variables globales
  341. extern int _hts_in_html_parsing;
  342. extern int _hts_in_html_done;  // % rΘalisΘs
  343. extern int _hts_in_html_poll;  // parsing
  344. extern char _hts_errmsg[1100];
  345. extern int _hts_setpause;
  346. //extern httrackp* _hts_setopt;
  347. extern char** _hts_addurl;
  348. extern int _hts_cancel;
  349. #endif
  350.  
  351. //
  352.  
  353.  
  354. //int httpmirror(char* url,int level,httrackp opt);
  355. int httpmirror(char* url1,httrackp* opt);
  356. int filesave(httrackp* opt,char* adr,int len,char* s,char* url_adr /* = NULL */,char* url_fil /* = NULL */);
  357. int check_fatal_io_errno(void);
  358. int engine_stats(void);
  359. void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,lien_back* back,int back_max,char* host);
  360. FILE* filecreate(char* s);
  361. int filecreateempty(char* filename);
  362. int filenote(char* s,filecreate_params* params);
  363. HTS_INLINE void usercommand(httrackp* opt,int exe,char* cmd,char* file,char* adr,char* fil);
  364. void usercommand_exe(char* cmd,char* file);
  365. //void* structcheck_init(int init);
  366. int filters_init(char*** ptrfilters, int maxfilter, int filterinc);
  367. #ifndef HTTRACK_DEFLIB
  368. HTSEXT_API int structcheck(char* s);
  369. #endif
  370. HTS_INLINE int fspc(FILE* fp,char* type);
  371. char* next_token(char* p,int flag);
  372. //
  373. char* readfile(char* fil);
  374. char* readfile_or(char* fil,char* defaultdata);
  375. #if 0
  376. void check_rate(TStamp stat_timestart,int maxrate);
  377. #endif
  378.  
  379. // liens
  380. int liens_record(char* adr,char* fil,char* save,char* former_adr,char* former_fil,char* codebase);
  381.  
  382.  
  383. // backing, routines externes
  384. int back_pluggable_sockets(lien_back* back, int back_max, httrackp* opt);
  385. int back_pluggable_sockets_strict(lien_back* back, int back_max, httrackp* opt);
  386. int back_fill(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  387. int backlinks_done(lien_url** liens,int lien_tot,int ptr);
  388. int back_fillmax(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  389.  
  390. // cancel file
  391. #if HTS_ANALYSTE
  392. #ifndef HTTRACK_DEFLIB
  393. HTSEXT_API char* hts_cancel_file(char * s);
  394. HTSEXT_API void hts_cancel_test(void);
  395. HTSEXT_API void hts_cancel_parsing(void);
  396. #endif
  397. #endif
  398.  
  399. int ask_continue(void);
  400. int nombre_digit(int n);
  401.  
  402. // Java
  403. #if 0
  404. int hts_add_file(char* file,int file_position);
  405. #endif
  406.  
  407. // Polling
  408. #if HTS_POLL
  409. HTS_INLINE int check_flot(T_SOC s);
  410. HTS_INLINE int check_stdin(void);
  411. int read_stdin(char* s,int max);
  412. #endif
  413. HTS_INLINE int check_sockerror(T_SOC s);
  414. HTS_INLINE int check_sockdata(T_SOC s);
  415.  
  416. httrackp* hts_declareoptbuffer(httrackp* optdecl);
  417. void sig_finish( int code );     // finir et quitter
  418. void sig_term( int code );       // quitter
  419. #if HTS_WIN
  420. void sig_ask( int code );        // demander
  421. #else
  422. void sig_back( int code );       // ignorer et mettre en backing 
  423. void sig_ask( int code );        // demander
  424. void sig_ignore( int code );     // ignorer signal
  425. void sig_brpipe( int code );     // treat if necessary
  426. void sig_doback(int);            // mettre en arriΦre plan
  427. #endif
  428.  
  429. /* external modules */
  430. int htsAddLink(htsmoduleStruct* str, char* link);
  431.  
  432. // Void
  433. void voidf(void);
  434.  
  435. #define HTS_TOPINDEX "TOP_INDEX_HTTRACK"
  436.  
  437. #endif
  438.  
  439. #endif
  440.  
  441.  
  442.